import os
import sys

# _path = os.path.join(os.path.abspath('..'), "opsFlask")
# print("add libs path:", _path)
# sys.path.insert(1, _path)

from flask_script import Manager, Server, Shell
from flask_migrate import Migrate, MigrateCommand

from app import create_app, db
from app.app_1_0.auth.models import User, Permission, Role, Menu
app = create_app("develop")
manager = Manager(app)
migrate = Migrate(app, db)


def make_shell_context():
    return dict(app=app, db=db, modules=[User, Permission, Role, Menu])


manager.add_command("shell", Shell(make_context=make_shell_context))
manager.add_command('db', MigrateCommand)
manager.add_command("runserver", Server(use_debugger=True, port=5001))

if __name__ == '__main__':
    print(app.url_map)
    for i in app.url_map.iter_rules():
        print(i.rule)
    manager.run()